package com.pai4j.aigc.service;

import com.pai4j.common.bean.PAIResponseBean;
import com.pai4j.common.bean.PAIResponseBeanUtil;
import com.pai4j.common.util.JsonUtil;
import com.pai4j.domain.vo.response.UserBaseResponseInfoVO;
import com.pai4j.domain.vo.response.UserBaseResponseVO;
import com.pai4j.remote.user.UserServiceClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserService {

    @Autowired
    private UserServiceClient userServiceClient;

    public UserBaseResponseInfoVO accountInfo(String account) {
        PAIResponseBean<UserBaseResponseInfoVO> responseBean = userServiceClient.getUserBaseInfo(account);
        if (PAIResponseBeanUtil.isOk(responseBean)) {
            return responseBean.getData();
        }
        log.error("获取用户信息远程调用异常 =====> account:{}, response:{}", account, JsonUtil.toJsonString(responseBean));
        return null;
    }

    /**
     * 根据用户名查询用户基础信息
     *
     * @param name
     * @return
     */
    public UserBaseResponseVO accountInfoByName(String name) {
        PAIResponseBean<UserBaseResponseVO> responseBean = userServiceClient.userNameBaseInfo(name);
        if (PAIResponseBeanUtil.isOk(responseBean)) {
            return responseBean.getData();
        }
        log.error("获取用户信息远程调用异常 =====> name:{}, response:{}", name, JsonUtil.toJsonString(responseBean));
        return null;
    }

}
